<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<div id="timer"></div>
		<button onclick="onStartClick();">开始</button>
		<button onclick="onStopClick();">停止</button>
		<script>
			function getCurTime() {
				let now = new Date();
				let hour = now.getHours();
				let minute = now.getMinutes();
				let second = now.getSeconds();
				hour = hour < 10 ? "0" + hour : hour;
				minute = minute < 10 ? "0" + minute : minute;
				second = second < 10 ? "0" + second : second;
				return hour + ":" + minute + ":" + second;
			}
			let lastPrintInfo = "";
			let callback = function() {

				let temp = getCurTime();
				if (lastPrintInfo == temp) {
					return;
				} else {
					// console.log(lastPrintInfo);
					timer.innerHTML = lastPrintInfo;
					lastPrintInfo = temp;
				}

			}
			let handler =null;
			function onStartClick(){
				 handler=setInterval(callback, 200);
			}
			function onStopClick(){
			     clearInterval(handler);
			}
			
		</script>
	</body>
</html>